// Player.js
// date: 2020-02-09
// 
//-
cc.Class({
    extends: cc.Component,

    properties: {
        pickRadius:0,
    },


    
    onLoad () {},

    start () {

    },

    update (dt) {

        if(this.getPlayerDistance() < this.pickRadius){
            this.onPicked();
            return;
        }

        let opacityRatio = 1 - this.game.timer /this.game.starDuration;
        let minOpacity = 50;
        this.node.opacity = minOpacity + Math.floor(opacityRatio * (255 - minOpacity));
    },

    getPlayerDistance(){

        let playerPos = this.game.player.getPosition()

        let dist = this.node.position.sub(playerPos).mag();

        return dist;
    },

    onPicked(){
        this.game.spawnNewStar();
        this.game.gainScore();
        this.node.destroy();
    }
});
